﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using acessaDB;
using Frame;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Estrutura;


namespace Banco
{

    /// <summary>
    /// Summary description for BD_Auditoria
    /// </summary>
    public class BD_Auditoria
    {
        #region variaveis_globais

        acessaDB.conectaDBMSSQLServer sqlServer = new conectaDBMSSQLServer();
        string conectionString = System.Configuration.ConfigurationManager.AppSettings["SQLServerConnectionLocal"];
        string usuario = string.Empty;

        #endregion

        #region construtor

        public BD_Auditoria()
        {
            if (System.Configuration.ConfigurationManager.AppSettings["ambiente"] == "PROD")
                conectionString = System.Configuration.ConfigurationManager.AppSettings["SQLServerConnectionProd"];
        }
        public BD_Auditoria(string usu_Login)
        {
            if (System.Configuration.ConfigurationManager.AppSettings["ambiente"] == "PROD")
                conectionString = System.Configuration.ConfigurationManager.AppSettings["SQLServerConnectionProd"];
            usuario = usu_Login;
        }

        #endregion

        #region metodos



        public string _excluir_Generico(string INTERFACE_ID_VALUE, 
                                        string INTERFACE, 
                                        string INTERFACE_ID_NAME = "", 
                                        string LOGICAL = "N", 
                                        string INTERFACE_EX_NAME = "",
                                        string UPDATE_ALL ="N")
        {
            string result = string.Empty;
            string sql = string.Empty;

            if (string.IsNullOrEmpty(INTERFACE_ID_NAME))
                INTERFACE_ID_NAME = INTERFACE + "_ID";

            if (string.IsNullOrEmpty(UPDATE_ALL))
                UPDATE_ALL = "N";

            if (UPDATE_ALL != "N")
            {
                sql = "UPDATE " + INTERFACE + " SET " + INTERFACE_EX_NAME + " = 1 ";
            }
            else
            {
                if (LOGICAL == "S")
                    sql = "UPDATE " + INTERFACE + " SET " + INTERFACE_EX_NAME + " = 1 WHERE " + INTERFACE_ID_NAME + " = " + INTERFACE_ID_VALUE;
                else
                    sql = "DELETE FROM " + INTERFACE + " WHERE " + INTERFACE_ID_NAME + " = " + INTERFACE_ID_VALUE;
            }
            try
            {
                sqlServer._ExecutarComandoRetornandoID(sql, conectionString, false, usuario);                
                return result;
            }
            catch (Exception e)
            {
                result = e.Message;
                return result;
            }
        }



        #endregion
    }
}